﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using OTS.BLL;

public partial class WebControl_Week_Ranking : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        BindSalesPro();
    }

    /// <summary>
    /// 一周销量排行
    /// </summary>
    private void BindSalesPro()
    {
        System.Text.StringBuilder sb1 = new System.Text.StringBuilder();
        System.Text.StringBuilder sb2 = new System.Text.StringBuilder();
        System.Text.StringBuilder sb3 = new System.Text.StringBuilder();
        System.Text.StringBuilder sb4 = new System.Text.StringBuilder();
        System.Text.StringBuilder sb5 = new System.Text.StringBuilder();
        SalesRecordBLL salesBLL = new SalesRecordBLL();
        DataTable dt = new DataTable();
        dt = salesBLL.GetSalesPro();
        string imgUrl = "";

        if (dt.Rows.Count > 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                switch (i)
                {
                    case 0:
                        sb1.Append("<div class='ginfo'>");
                        sb1.Append("<span class='num'>1</span>");
                        sb1.Append("<span class='text'>");
                        sb1.AppendFormat("<a href='product.aspx?proID={0}' target='_blank'>{1}</a>", dt.Rows[i]["proID"].ToString(), dt.Rows[i]["title"].ToString());
                        sb1.Append("</span>");
                        if (dt.Rows[i]["retailPrice"].ToString() != "0")
                        {
                            sb1.AppendFormat("<span class='price'>￥{0}</span>", dt.Rows[i]["retailPrice"].ToString());
                        }
                        else
                        {
                            sb1.AppendFormat("<span class='price'>￥{0}</span>", dt.Rows[i]["wholeSalePrice"].ToString());
                        }
                        sb1.Append("</div>");
                        sb1.Append("<div class='gimg'>");
                        sb1.AppendFormat("<a href='product.aspx?proID={0}' target='_blank'>", dt.Rows[i]["proID"].ToString());
                        imgUrl = System.Web.HttpContext.Current.Server.MapPath(dt.Rows[i]["bigImg_pic"].ToString());
                        sb1.AppendFormat("<img alt='{0} {1}' src='{2}' />", dt.Rows[i]["title"].ToString(), dt.Rows[i]["proID"].ToString(), imgUrl);
                        sb1.Append("</a>");
                        sb1.Append("</div>");
                        this.SalesPro1.InnerHtml = sb1.ToString();
                        break;
                    case 1:
                        sb2.Append("<div class='ginfo'>");
                        sb2.Append("<span class='num'>2</span>");
                        sb2.Append("<span class='text'>");
                        sb2.AppendFormat("<a href='product.aspx?proID={0}' target='_blank'>{1}</a>", dt.Rows[i]["proID"].ToString(), dt.Rows[i]["title"].ToString());
                        sb2.Append("</span>");
                        if (dt.Rows[i]["retailPrice"].ToString() != "0")
                        {
                            sb2.AppendFormat("<span class='price'>￥{0}</span>", dt.Rows[i]["retailPrice"].ToString());
                        }
                        else
                        {
                            sb2.AppendFormat("<span class='price'>￥{0}</span>", dt.Rows[i]["wholeSalePrice"].ToString());
                        }
                        sb2.Append("</div>");
                        sb2.Append("<div class='gimg'>");
                        sb2.AppendFormat("<a href='product.aspx?proID={0}' target='_blank'>", dt.Rows[i]["proID"].ToString());
                        imgUrl = System.Web.HttpContext.Current.Server.MapPath(dt.Rows[i]["bigImg_pic"].ToString());
                        sb2.AppendFormat("<img alt='{0} {1}' src='{2}' />", dt.Rows[i]["title"].ToString(), dt.Rows[i]["proID"].ToString(), imgUrl);
                        sb2.Append("</a>");
                        sb2.Append("</div>");
                        this.SalesPro2.InnerHtml = sb2.ToString();
                        break;
                    case 2:
                        sb3.Append("<div class='ginfo'>");
                        sb3.Append("<span class='num'>3</span>");
                        sb3.Append("<span class='text'>");
                        sb3.AppendFormat("<a href='product.aspx?proID={0}' target='_blank'>{1}</a>", dt.Rows[i]["proID"].ToString(), dt.Rows[i]["title"].ToString());
                        sb3.Append("</span>");
                        if (dt.Rows[i]["retailPrice"].ToString() != "0")
                        {
                            sb3.AppendFormat("<span class='price'>￥{0}</span>", dt.Rows[i]["retailPrice"].ToString());
                        }
                        else
                        {
                            sb3.AppendFormat("<span class='price'>￥{0}</span>", dt.Rows[i]["wholeSalePrice"].ToString());
                        }
                        sb3.Append("</div>");
                        sb3.Append("<div class='gimg'>");
                        sb3.AppendFormat("<a href='product.aspx?proID={0}' target='_blank'>", dt.Rows[i]["proID"].ToString());
                        imgUrl = System.Web.HttpContext.Current.Server.MapPath(dt.Rows[i]["bigImg_pic"].ToString());
                        sb3.AppendFormat("<img alt='{0} {1}' src='{2}' />", dt.Rows[i]["title"].ToString(), dt.Rows[i]["proID"].ToString(), imgUrl);
                        sb3.Append("</a>");
                        sb3.Append("</div>");
                        this.SalesPro3.InnerHtml = sb3.ToString();
                        break;
                    case 3:
                        sb4.Append("<div class='ginfo'>");
                        sb4.Append("<span class='num'>4</span>");
                        sb4.Append("<span class='text'>");
                        sb4.AppendFormat("<a href='product.aspx?proID={0}' target='_blank'>{1}</a>", dt.Rows[i]["proID"].ToString(), dt.Rows[i]["title"].ToString());
                        sb4.Append("</span>");
                        if (dt.Rows[i]["retailPrice"].ToString() != "0")
                        {
                            sb4.AppendFormat("<span class='price'>￥{0}</span>", dt.Rows[i]["retailPrice"].ToString());
                        }
                        else
                        {
                            sb4.AppendFormat("<span class='price'>￥{0}</span>", dt.Rows[i]["wholeSalePrice"].ToString());
                        }
                        sb4.Append("</div>");
                        sb4.Append("<div class='gimg'>");
                        sb4.AppendFormat("<a href='product.aspx?proID={0}' target='_blank'>", dt.Rows[i]["proID"].ToString());
                        imgUrl = System.Web.HttpContext.Current.Server.MapPath(dt.Rows[i]["bigImg_pic"].ToString());
                        sb4.AppendFormat("<img alt='{0} {1}' src='{2}' />", dt.Rows[i]["title"].ToString(), dt.Rows[i]["proID"].ToString(), imgUrl);
                        sb4.Append("</a>");
                        sb4.Append("</div>");
                        this.SalesPro4.InnerHtml = sb4.ToString();
                        break;
                    default:
                        sb5.Append("<div class='ginfo'>");
                        sb5.Append("<span class='num'>5</span>");
                        sb5.Append("<span class='text'>");
                        sb5.AppendFormat("<a href='product.aspx?proID={0}' target='_blank'>{1}</a>", dt.Rows[i]["proID"].ToString(), dt.Rows[i]["title"].ToString());
                        sb5.Append("</span>");
                        if (dt.Rows[i]["retailPrice"].ToString() != "0")
                        {
                            sb5.AppendFormat("<span class='price'>￥{0}</span>", dt.Rows[i]["retailPrice"].ToString());
                        }
                        else
                        {
                            sb5.AppendFormat("<span class='price'>￥{0}</span>", dt.Rows[i]["wholeSalePrice"].ToString());
                        }
                        sb5.Append("</div>");
                        sb5.Append("<div class='gimg'>");
                        sb5.AppendFormat("<a href='product.aspx?proID={0}' target='_blank'>", dt.Rows[i]["proID"].ToString());
                        imgUrl = System.Web.HttpContext.Current.Server.MapPath(dt.Rows[i]["bigImg_pic"].ToString());
                        sb5.AppendFormat("<img alt='{0} {1}' src='{2}' />", dt.Rows[i]["title"].ToString(), dt.Rows[i]["proID"].ToString(), imgUrl);
                        sb5.Append("</a>");
                        sb5.Append("</div>");
                        this.SalesPro5.InnerHtml = sb5.ToString();
                        break;
                }
            }
        }
        else
        {
            this.Panel1.Visible = false;
            this.lblPaihang.Text = "暂无销量排行";
        }
    }
}
